home *** CD-ROM | disk | FTP | other *** search
-
- /* @(#)rev_iycp.c 1.7 91/11/07
- *
- * Copyright (C) 1990, 1991 - Yves Gallot - all rights reserved.
- *
- * Permission is granted to copy this source, for redistribution
- * in source form only, provided the news headers in "substantially
- * unaltered format" are retained, the introductory messages are not
- * removed, and no monies are exchanged.
- *
- * Permission is also granted to copy this source, without the
- * news headers, for the purposes of making an executable copy by
- * means of compilation, provided that such copy will not be used
- * for the purposes of competition in any othello tournaments, without
- * prior permission from the authors.
- *
- * No responsibility is taken for any errors on inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file), then an attempt will be made to fix them.
- */
-
- #include "reve.h"
-
- extern int damier[NIVEAUMAX][64] ;
- extern int tacouleur, macouleur ;
- extern int vp0, vo0 ;
-
- /* Functions used by the "fast" alpha-beta pruning.
- * - JePeuxJouer( niv ) and TuPeuxJouer( niv ) :
- * Test if I Can Play or You Can Play on the Board number niv ( which is
- * current board at depth niv ). "I" is for macouleur value ( my color )
- * and "You" for tacouleur value ( your color ). Return TRUE or FALSE.
- * If TRUE, put JPJ on every squares where I Can Play, or TPJ on every
- * squares where You Can Play.
- * - JeJoueen( x, y, niv ) and TuJouesen( x, y, niv ) :
- * I Play square (x, y) on Board number niv and You Play square (x, y)
- * on Board number niv. It puts piece color macouleur or tacouleur and
- * returns pieces that must be.
- */
-
- int
- jepeuxjouer(niv)
- int niv ;
- {
- register int *d ;
- register int x, y, posx, posy, pos8x, poscr, flag ;
-
- d = damier[niv] ;
- flag = FALSE ;
- vp0 = 0 ;
-
- for (posx = 0; posx < 8; posx++)
- {
- pos8x = posx << 3 ;
- for (posy = 0; posy < 8; posy++)
- {
- poscr = pos8x + posy;
- if ((d[poscr] == TPJ) || (d[poscr] == JPJ)) d[poscr] = FREE ;
- if (d[poscr] == FREE)
- {
-
- for (x = posx + 1;
- (x < 7) && (d[(x << 3) + posy] == tacouleur);
- x++) continue ;
- if ((x != posx + 1) && (d[(x << 3) + posy] == macouleur))
- {
- flag = TRUE ;
- d[poscr] = JPJ ;
- vp0++ ;
- goto endloopj ;
- }
-
- for (x = posx - 1;
- (x > 0) && (d[(x << 3) + posy] == tacouleur);
- x--) continue ;
- if ((x != posx - 1) && (d[(x << 3) + posy] == macouleur))
- {
- flag = TRUE ;
- d[poscr] = JPJ ;
- vp0++ ;
- goto endloopj ;
- }
-
- for (y = posy + 1;
- (y < 7) && (d[pos8x + y] == tacouleur);
- y++) continue ;
- if ((y != posy + 1) && (d[pos8x + y] == macouleur))
- {
- flag = TRUE ;
- d[poscr] = JPJ ;
- vp0++ ;
- goto endloopj ;
- }
-
- for (y = posy - 1;
- (y > 0) && (d[pos8x + y] == tacouleur);
- y--) continue ;
- if ((y != posy - 1) && (d[pos8x + y] == macouleur))
- {
- flag = TRUE ;
- d[poscr] = JPJ ;
- vp0++ ;
- goto endloopj ;
- }
-
- for (x = posx + 1, y = posy + 1;
- (x < 7) && (y < 7) && (d[(x << 3) + y] == tacouleur);
- x++, y++) continue ;
- if ((x != posx + 1) && (d[(x << 3) + y] == macouleur))
- {
- flag = TRUE ;
- d[poscr] = JPJ ;
- vp0++ ;
- goto endloopj ;
- }
-
- for (x = posx - 1, y = posy + 1;
- (x > 0) && (y < 7) && (d[(x << 3) + y] == tacouleur);
- x--, y++) continue ;
- if ((x != posx - 1) && (d[(x << 3) + y] == macouleur))
- {
- flag = TRUE ;
- d[poscr] = JPJ ;
- vp0++ ;
- goto endloopj ;
- }
-
- for (x = posx + 1, y = posy - 1;
- (x < 7) && (y > 0) && (d[(x << 3) + y] == tacouleur);
- x++, y--) continue ;
- if ((x != posx + 1) && (d[(x << 3) + y] == macouleur))
- {
- flag = TRUE ;
- d[poscr] = JPJ ;
- vp0++ ;
- goto endloopj ;
- }
-
- for (x = posx - 1, y = posy - 1;
- (x > 0) && (y > 0) && (d[(x << 3) + y] == tacouleur);
- x--, y--) continue ;
- if ((x != posx - 1) && (d[(x << 3) + y] == macouleur))
- {
- flag = TRUE ;
- d[poscr] = JPJ ;
- vp0++ ;
- }
- endloopj: ;
- }
- }
- }
- return flag ;
- }
-
-
- int
- jejoueen(posx, posy, niv)
- int posx, posy, niv ;
- {
- register int *d ;
- register int x, y, pos8x ;
-
- pos8x = posx << 3 ;
-
- d = damier[niv] ;
-
- d[pos8x + posy] = macouleur ;
-
- for (x = posx + 1;
- (x < 7) && (d[(x << 3) + posy] == tacouleur); x++) continue ;
- if ((x != posx + 1) && (d[(x << 3) + posy] == macouleur))
- {
- for (x = posx + 1; d[(x << 3) + posy] == tacouleur; x++)
- d[(x << 3) + posy] = macouleur ;
- }
-
- for (x = posx - 1;
- (x > 0) && (d[(x << 3) + posy] == tacouleur); x--) continue ;
- if ((x != posx - 1) && (d[(x << 3) + posy] == macouleur))
- {
- for (x = posx - 1; d[(x << 3) + posy] == tacouleur; x--)
- d[(x << 3) + posy] = macouleur ;
- }
-
- for (y = posy + 1;
- (y < 7) && (d[pos8x + y] == tacouleur); y++) continue ;
- if ((y != posy + 1) && (d[pos8x + y] == macouleur))
- {
- for (y = posy + 1; d[pos8x + y] == tacouleur; y++)
- d[pos8x + y] = macouleur ;
- }
-
- for (y = posy - 1;
- (y > 0) && (d[pos8x + y] == tacouleur); y--) continue ;
- if ((y != posy - 1) && (d[pos8x + y] == macouleur))
- {
- for (y = posy - 1; d[pos8x + y] == tacouleur; y--)
- d[pos8x + y] = macouleur ;
- }
-
- for (x = posx + 1, y = posy + 1;
- (x < 7) && (y < 7) && (d[(x << 3) + y] == tacouleur);
- x++, y++) continue ;
- if ((x != posx + 1) && (d[(x << 3) + y] == macouleur))
- {
- for (x = posx + 1, y = posy + 1; d[(x << 3) + y] == tacouleur; x++, y++)
- d[(x << 3) + y] = macouleur ;
- }
-
- for (x = posx - 1, y = posy + 1;
- (x > 0) && (y < 7) && (d[(x << 3) + y] == tacouleur);
- x--, y++) continue ;
- if ((x != posx - 1) && (d[(x << 3) + y] == macouleur))
- {
- for (x = posx - 1, y = posy + 1; d[(x << 3) + y] == tacouleur; x--, y++)
- d[(x << 3) + y] = macouleur ;
- }
-
- for (x = posx + 1, y = posy - 1;
- (x < 7) && (y > 0) && (d[(x << 3) + y] == tacouleur);
- x++, y--) continue ;
- if ((x != posx + 1) && (d[(x << 3) + y] == macouleur))
- {
- for (x = posx + 1, y = posy - 1; d[(x << 3) + y] == tacouleur; x++, y--)
- d[(x << 3) + y] = macouleur ;
- }
-
- for (x = posx - 1, y = posy - 1;
- (x > 0) && (y > 0) && (d[(x << 3) + y] == tacouleur);
- x--, y--) continue ;
- if ((x != posx - 1) && (d[(x << 3) + y] == macouleur))
- {
- for (x = posx - 1, y = posy - 1; d[(x << 3) + y] == tacouleur; x--, y--)
- d[(x << 3) + y] = macouleur ;
- }
- }
-
-
- int
- tupeuxjouer(niv)
- int niv ;
- {
- register int *d ;
- register int x, y, posx, posy, pos8x, poscr, flag ;
-
- d = damier[niv] ;
- flag = FALSE ;
- vo0 = 0 ;
-
- for (posx = 0; posx < 8; posx++)
- {
- pos8x = posx << 3 ;
- for (posy = 0; posy < 8; posy++)
- {
- poscr = pos8x + posy ;
- if ((d[poscr] == TPJ) || (d[poscr] == JPJ)) d[poscr] = FREE ;
- if (d[poscr] == FREE)
- {
- for (x = posx + 1;
- (x < 7) && (d[(x << 3) + posy] == macouleur);
- x++) continue ;
- if ((x != posx + 1) && (d[(x << 3) + posy] == tacouleur))
- {
- flag = TRUE ;
- d[poscr] = TPJ ;
- vo0++ ;
- goto endloopt ;
- }
-
- for (x = posx - 1;
- (x > 0) && (d[(x << 3) + posy] == macouleur) ;
- x--) continue ;
- if ((x != posx - 1) && (d[(x << 3) + posy] == tacouleur))
- {
- flag = TRUE ;
- d[poscr] = TPJ ;
- vo0++ ;
- goto endloopt ;
- }
-
- for (y = posy + 1;
- (y < 7) && (d[pos8x + y] == macouleur);
- y++) continue ;
- if ((y != posy + 1) && (d[pos8x + y] == tacouleur))
- {
- flag = TRUE ;
- d[poscr] = TPJ ;
- vo0++ ;
- goto endloopt ;
- }
-
- for (y = posy - 1;
- (y > 0) && (d[pos8x + y] == macouleur);
- y--) continue ;
- if ((y != posy - 1) && (d[pos8x + y] == tacouleur))
- {
- flag = TRUE ;
- d[poscr] = TPJ ;
- vo0++ ;
- goto endloopt ;
- }
-
- for (x = posx + 1, y = posy + 1;
- (x < 7) && (y < 7) && (d[(x << 3) + y] == macouleur);
- x++, y++) continue ;
- if ((x != posx + 1) && (d[(x << 3) + y] == tacouleur))
- {
- flag = TRUE ;
- d[poscr] = TPJ ;
- vo0++ ;
- goto endloopt ;
- }
-
- for (x = posx - 1, y = posy + 1;
- (x > 0) && (y < 7) && (d[(x << 3) + y] == macouleur);
- x--, y++) continue ;
- if ((x != posx - 1) && (d[(x << 3) + y] == tacouleur))
- {
- flag = TRUE ;
- d[poscr] = TPJ ;
- vo0++ ;
- goto endloopt ;
- }
-
- for (x = posx + 1, y = posy - 1;
- (x < 7) && (y > 0) && (d[(x << 3) + y] == macouleur);
- x++, y--) continue ;
- if ((x != posx + 1) && (d[(x << 3) + y] == tacouleur))
- {
- flag = TRUE ;
- d[poscr] = TPJ ;
- vo0++ ;
- goto endloopt ;
- }
-
- for (x = posx - 1, y = posy - 1;
- (x > 0) && (y > 0) && (d[(x << 3) + y] == macouleur) ;
- x--, y-- ) continue ;
- if ((x != posx - 1) && (d[(x << 3) + y] == tacouleur))
- {
- flag = TRUE ;
- d[poscr] = TPJ ;
- vo0++ ;
- }
- endloopt: ;
- }
- }
- }
- return(flag) ;
- }
-
-
- int
- tujouesen(posx, posy, niv)
- int posx, posy, niv ;
- {
- register int *d ;
- register int x, y, pos8x ;
-
- pos8x = posx << 3 ;
- d = damier[niv] ;
- d[pos8x + posy] = tacouleur ;
-
- for (x = posx + 1;
- (x < 7) && (d[(x << 3) + posy] == macouleur); x++) continue ;
- if ((x != posx + 1) && (d[(x << 3) + posy] == tacouleur))
- {
- for (x = posx + 1; d[(x << 3) + posy] == macouleur; x++)
- d[(x << 3) + posy] = tacouleur ;
- }
-
- for (x = posx - 1;
- (x > 0) && (d[(x << 3) + posy] == macouleur); x--) continue ;
- if ((x != posx - 1) && (d[(x << 3) + posy] == tacouleur))
- {
- for (x = posx - 1; d[(x << 3) + posy] == macouleur; x--)
- d[(x << 3) + posy] = tacouleur ;
- }
-
- for (y = posy + 1;
- (y < 7) && (d[pos8x + y] == macouleur); y++) continue ;
- if ((y != posy + 1) && (d[pos8x + y] == tacouleur))
- {
- for (y = posy + 1; d[pos8x + y] == macouleur; y++)
- d[pos8x + y] = tacouleur ;
- }
-
- for (y = posy - 1;
- (y > 0) && (d[pos8x + y] == macouleur); y--) continue ;
- if ((y != posy - 1) && (d[pos8x + y] == tacouleur))
- {
- for (y = posy - 1; d[pos8x + y] == macouleur; y--)
- d[pos8x + y] = tacouleur ;
- }
-
- for (x = posx + 1, y = posy + 1;
- (x < 7) && (y < 7) && (d[(x << 3) + y] == macouleur);
- x++, y++) continue ;
- if ((x != posx + 1) && (d[(x << 3) + y] == tacouleur))
- {
- for (x = posx + 1, y = posy + 1; d[(x << 3) + y] == macouleur; x++, y++)
- d[(x << 3) + y] = tacouleur ;
- }
-
- for (x = posx - 1, y = posy + 1;
- (x > 0) && (y < 7) && (d[(x << 3) + y] == macouleur);
- x--, y++) continue ;
- if ((x != posx - 1) && (d[(x << 3) + y] == tacouleur))
- {
- for (x = posx - 1, y = posy + 1; d[(x << 3) + y] == macouleur; x--, y++)
- d[(x << 3) + y] = tacouleur ;
- }
-
- for (x = posx + 1, y = posy - 1;
- (x < 7) && (y > 0) && (d[(x << 3) + y] == macouleur);
- x++, y--) continue ;
- if ((x != posx + 1) && (d[(x << 3) + y] == tacouleur))
- {
- for (x = posx + 1, y = posy - 1; d[(x << 3) + y] == macouleur; x++, y--)
- d[(x << 3) + y] = tacouleur ;
- }
-
- for (x = posx - 1, y = posy - 1;
- (x > 0) && (y > 0) && (d[(x << 3) + y] == macouleur);
- x--, y--) continue ;
- if ((x != posx - 1) && (d[(x << 3) + y] == tacouleur))
- {
- for (x = posx - 1, y = posy - 1; d[(x << 3) + y] == macouleur; x--, y--)
- d[(x << 3) + y] = tacouleur ;
- }
- }
-